package com.code4j.tree;

import java.util.Observable;
import java.util.Observer;

import javax.swing.JLabel;

import com.code4j.tree.BinaryTree.Node;

public class BinaryTreeStatus extends JLabel implements Observer{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Override
	public void update(Observable o, Object arg) {
		if(arg instanceof String){
			String string = (String) arg;
			if(string.equals("clear")){
				setText("");
			}else
				setText(string);
			
		}else if(arg instanceof Node){
			Node node = (Node) arg;
			StringBuilder sb = new StringBuilder(getText());
			sb.append(node.data+"   ");
			setText(sb.toString());
		}
	}

}
